package org.idea.spring.condition.expressioninject;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author linhao
 * @Date created in 2:46 下午 2021/5/8
 */
@Configuration
public class ExpressAutoConfig {

    /**
     * 某些特殊场景下可能需要按照表达式规则来进行依赖注入
     *
     * @return
     */
    @Bean
    @ConditionalOnExpression("#{'true'.equals(environment['express.value'])}")
    public ExpressTrueBean expressTrueBean(){
        return new ExpressTrueBean();
    }


    @Bean
    @ConditionalOnExpression("#{!'true'.equals(environment['express.value'])}")
    public ExpressFalseBean expressFalseBean(){
        return new ExpressFalseBean();
    }
}
